package com.taotao.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.taotao.common.pojo.EasyUITreeNode;
import com.taotao.common.pojo.TaotaoResult;
import com.taotao.content.service.ContentCategoryService;

/**
 * 内容分类controller
 * @author Administrator
 *
 */
@Controller
@RequestMapping("/content/category")
public class ContentCategoryController {

	@Autowired
	private ContentCategoryService contentCategoryService;
	
	//内容分类目录列表
	@RequestMapping("/list")
	@ResponseBody
	public List<EasyUITreeNode> getContentCategoryList(@RequestParam(value="id",defaultValue="0")Long parentId){
		List<EasyUITreeNode> list = contentCategoryService.getContentCategoryList(parentId);
		return list;
	}
	
	//增加分类
	@RequestMapping("/create")
	@ResponseBody
	public TaotaoResult insertContentCategory(Long parentId,String name){
		
		TaotaoResult taotaoResult = contentCategoryService.insertContentCategory(parentId, name);
		return taotaoResult;
	}
	
	//更新分类
	@RequestMapping("/update")
	public void updateContentCategory(Long id,String name){
		contentCategoryService.updateContentCategory(id,name);
	}
	
	//删除
	@RequestMapping("/delete")
	public String  deleteContentCategory(Long id){
		contentCategoryService.deleteContentCategory(id);
		return "redirect:/content/category/list";
	}
}
